package com.youdelu.form.view;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;

import com.youdelu.form.R;
import com.youdelu.form.util.DisplayUtil;


public class TipsView extends AppCompatTextView {
    public TipsView(Context context) {
        super(context);
    }

    public TipsView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public TipsView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    public void setText(String text, boolean isError){
        int drawableId,color;
        if(isError){
            drawableId = R.mipmap.icon_warn_red;
            color = R.color.warn_red;
        }else{
            drawableId = R.mipmap.icon_warn_yellow;
            color = R.color.warn_yellow;
        }
        Drawable drawable = getResources().getDrawable(drawableId);
        drawable.setBounds(0, DisplayUtil.dip2px(getContext(),1f), drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        setCompoundDrawables(drawable,null,null,null);
        setCompoundDrawablePadding(DisplayUtil.dip2px(getContext(),5f));
        setTextColor(getResources().getColor(color));
        super.setText(text);
    }

    public void setText(String text){
        if(text.contains("重复")||text.contains("为空")){
            setText(text,true);
        }else{
            setText(text,false);
        }
    }
}
